﻿<UserControl x:Class="GTServices.WPF.Client.Views.ManageView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
             xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
             xmlns:ext="clr-namespace:GTServices.WPF.Client.Extensions"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="700">
    
    <DockPanel>
        <Menu DockPanel.Dock="Top">
            <MenuItem x:Name="Import" Header="Import">
                <MenuItem x:Name="ImportEntityXml" Header="EntityXml" />
                <MenuItem Header="Patterns">
                    <MenuItem x:Name="ImportPatternsFromTxt" Header="FromTxt" />
                </MenuItem>
            </MenuItem>
            <MenuItem Header="Database">
                <MenuItem Header="Save" x:Name="Save" />
            </MenuItem>
        </Menu>
        <Grid DockPanel.Dock="Bottom">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="40*" />
                <ColumnDefinition Width="5" />
                <!-- Grid Splitter -->
                <ColumnDefinition Width="55*" />
            </Grid.ColumnDefinitions>

            <!--Note to self: fix this, i can be more clever in my Template usage and leave it to the selectedTab to insert ther proper ListView. This is all redundent.. =/-->
            <TabControl Grid.Column="0" TabStripPlacement="Left"
                        cal:Message.Attach="[Event SelectionChanged] = [Action TabControlSelectionChanged($executionContext]">
                <TabControl.Resources>
                    <!-- Default Control template slightly modified -->
                    <Style x:Key="TabItemFocusVisual">
                        <Setter Property="Control.Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Rectangle Margin="3,3,3,1"
                               StrokeThickness="1"
                               Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
                               StrokeDashArray="1 2"
                               SnapsToDevicePixels="true"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>




                    <LinearGradientBrush x:Key="TabItemHotBackground"
                         StartPoint="0,0"
                         EndPoint="0,1">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Color="#EAF6FD"
                          Offset="0.15"/>
                            <GradientStop Color="#D9F0FC"
                          Offset=".5"/>
                            <GradientStop Color="#BEE6FD"
                          Offset=".5"/>
                            <GradientStop Color="#A7D9F5"
                          Offset="1"/>
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                    <SolidColorBrush x:Key="TabItemSelectedBackground"
                     Color="#F9F9F9"/>
                    <SolidColorBrush x:Key="TabItemDisabledBackground"
                     Color="#F4F4F4"/>
                    <SolidColorBrush x:Key="TabItemHotBorderBrush"
                     Color="#3C7FB1"/>
                    <SolidColorBrush x:Key="TabItemDisabledBorderBrush"
                     Color="#FFC9C7BA"/>
                    <Style TargetType="{x:Type TabItem}">
                        <Setter Property="Padding" Value="4" />
                        <Setter Property="HeaderTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <ContentPresenter Content="{TemplateBinding Content}">
                                        <ContentPresenter.LayoutTransform>
                                            <RotateTransform Angle="90" />
                                        </ContentPresenter.LayoutTransform>
                                    </ContentPresenter>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type TabItem}">
                                    <Grid SnapsToDevicePixels="true">
                                        <Border Name="Bd"
                                            Padding="{TemplateBinding Padding}"
                                            BorderBrush="{TemplateBinding BorderBrush}"
                                            Background="{TemplateBinding Background}"
                                            BorderThickness="1,1,1,0"
                                            CornerRadius="6,0,0,6"
                                            >
                                            <ContentPresenter Name="Content"
                                              ContentSource="Header"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                              HorizontalAlignment="{Binding Path=HorizontalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
                                              VerticalAlignment="{Binding Path=VerticalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
                                              RecognizesAccessKey="True"/>
                                        </Border>
                                    </Grid>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver"
                                 Value="true">
                                            <Setter TargetName="Bd"
                                    Property="Background"
                                    Value="{StaticResource TabItemHotBackground}"/>
                                        </Trigger>
                                        <Trigger Property="IsSelected"
                                 Value="true">
                                            <Setter Property="Panel.ZIndex"
                                    Value="1"/>
                                            <Setter TargetName="Bd"
                                    Property="Background"
                                    Value="{StaticResource TabItemSelectedBackground}"/>
                                        </Trigger>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="IsSelected"
                                           Value="false"/>
                                                <Condition Property="IsMouseOver"
                                           Value="true"/>
                                            </MultiTrigger.Conditions>
                                            <Setter TargetName="Bd"
                                    Property="BorderBrush"
                                    Value="{StaticResource TabItemHotBorderBrush}"/>
                                        </MultiTrigger>
                                        <Trigger Property="TabStripPlacement"
                                 Value="Bottom">
                                            <Setter TargetName="Bd"
                                    Property="BorderThickness"
                                    Value="1,0,1,1"/>
                                        </Trigger>
                                        <Trigger Property="TabStripPlacement"
                                 Value="Left">
                                            <Setter TargetName="Bd"
                                    Property="BorderThickness"
                                    Value="1,1,0,1"/>
                                        </Trigger>
                                        <Trigger Property="TabStripPlacement"
                                 Value="Right">
                                            <Setter TargetName="Bd"
                                    Property="BorderThickness"
                                    Value="0,1,1,1"/>
                                        </Trigger>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="IsSelected"
                                           Value="true"/>
                                                <Condition Property="TabStripPlacement"
                                           Value="Top"/>
                                            </MultiTrigger.Conditions>
                                            <Setter Property="Margin"
                                    Value="-2,-2,-2,-1"/>
                                            <Setter TargetName="Content"
                                    Property="Margin"
                                    Value="0,0,0,1"/>
                                        </MultiTrigger>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="IsSelected"
                                           Value="true"/>
                                                <Condition Property="TabStripPlacement"
                                           Value="Bottom"/>
                                            </MultiTrigger.Conditions>
                                            <Setter Property="Margin"
                                    Value="-2,-1,-2,-2"/>
                                            <Setter TargetName="Content"
                                    Property="Margin"
                                    Value="0,1,0,0"/>
                                        </MultiTrigger>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="IsSelected"
                                           Value="true"/>
                                                <Condition Property="TabStripPlacement"
                                           Value="Left"/>
                                            </MultiTrigger.Conditions>
                                            <Setter Property="Margin"
                                    Value="-2,-2,-1,-2"/>
                                            <Setter TargetName="Content"
                                    Property="Margin"
                                    Value="0,0,1,0"/>
                                        </MultiTrigger>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="IsSelected"
                                           Value="true"/>
                                                <Condition Property="TabStripPlacement"
                                           Value="Right"/>
                                            </MultiTrigger.Conditions>
                                            <Setter Property="Margin"
                                    Value="-1,-2,-2,-2"/>
                                            <Setter TargetName="Content"
                                    Property="Margin"
                                    Value="1,0,0,0"/>
                                        </MultiTrigger>
                                        <Trigger Property="IsEnabled"
                                 Value="false">
                                            <Setter TargetName="Bd"
                                    Property="Background"
                                    Value="{StaticResource TabItemDisabledBackground}"/>
                                            <Setter TargetName="Bd"
                                    Property="BorderBrush"
                                    Value="{StaticResource TabItemDisabledBorderBrush}"/>
                                            <Setter Property="Foreground"
                                    Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </TabControl.Resources>
                <TabItem Header="Categories">
                    <ListView ItemsSource="{Binding Categories}" 
                              cal:Message.Attach="[Event SelectionChanged] = [Action SelectedItemChanged($executionContext, 'Category')]"
                              ext:GridViewSort.AutoSort="True">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Name"            
                                                DisplayMemberBinding="{Binding Name}"
                                                ext:GridViewSort.PropertyName="Name"/>
                                <GridViewColumn Header="#Patterns"            
                                                DisplayMemberBinding="{Binding Patterns.Count}"
                                                ext:GridViewSort.PropertyName="Patterns.Count"/>

                                <GridViewColumn Header="Classification"  
                                                DisplayMemberBinding="{Binding Classification.Name}"
                                                ext:GridViewSort.PropertyName="Classification.Name"/>
                                <GridViewColumn Header="Template"        
                                                DisplayMemberBinding="{Binding Template.Name}"
                                                ext:GridViewSort.PropertyName="Template.Name"/>
                            </GridView>
                        </ListView.View>
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Add"    cal:Message.Attach="Add('Category')" />
                                <MenuItem Header="Remove" cal:Message.Attach="RemoveSelectedItems()" />
                                <MenuItem Header="Export" cal:Message.Attach="ExportSelectedItems()" />
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>
                </TabItem>
                <TabItem Header="Patterns">
                    <ListView ItemsSource="{Binding Patterns}"  
                              cal:Message.Attach="[Event SelectionChanged] = [Action SelectedItemChanged($executionContext, 'Pattern')];[Event OnFocus] = [Action OnFocus()]"
                              ext:GridViewSort.AutoSort="True">
                        <ListView.ItemContainerStyle>
                            <Style TargetType="{x:Type ListViewItem}">
                                <Setter Property="ToolTip" Value="{Binding CategoriesAsString}" />
                                <Setter Property="cal:Message.Attach" Value="" />
                            </Style>
                        </ListView.ItemContainerStyle>
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Pattern" 
                                                DisplayMemberBinding="{Binding Pattern.PatternStr}"
                                                ext:GridViewSort.PropertyName="Pattern.PatternStr"
                                                />
                                <GridViewColumn Header="Language" 
                                                DisplayMemberBinding="{Binding Language.Name}"
                                                ext:GridViewSort.PropertyName="Language.Name"
                                                />
                                <GridViewColumn Header="First Category" 
                                                DisplayMemberBinding="{Binding FirstCategoryIfExists}"
                                                ext:GridViewSort.PropertyName="FirstCategoryIfExists"
                                                />
                            </GridView>
                        </ListView.View>
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Add" cal:Message.Attach="Add('Pattern')" />
                                <MenuItem Header="Remove" cal:Message.Attach="RemoveSelectedItems()" />
                                <MenuItem Header="Export" cal:Message.Attach="ExportSelectedItems()" />
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>
                </TabItem>
                <TabItem Header="Languages">
                    <ListView ItemsSource="{Binding Languages}" 
                              SelectedItem="{Binding SelectedViewModel}"
                              ext:GridViewSort.AutoSort="True">
                        <ListView.View>
                            <GridView>
                             
                                <GridViewColumn Header="Name" 
                                                DisplayMemberBinding="{Binding Name}"
                                                ext:GridViewSort.PropertyName="Name"/>
                            </GridView>
                        </ListView.View>
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Add" cal:Message.Attach="Add('Language')" />
                                <MenuItem Header="Remove" cal:Message.Attach="RemoveSelectedItems()" />
                                <MenuItem Header="Export" cal:Message.Attach="ExportSelectedItems()" />
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>
                </TabItem>
                <TabItem Header="Extensions">
                    <ListView ItemsSource="{Binding FileExtensions}" 
                              SelectedItem="{Binding SelectedViewModel}"
                              ext:GridViewSort.AutoSort="True">
                        <ListView.View>
                            <GridView>
                               
                                <GridViewColumn Header="Extension" 
                                                DisplayMemberBinding="{Binding FileExtension.Extension}"
                                                ext:GridViewSort.PropertyName="FileExtension.Extension"/>
                            </GridView>
                        </ListView.View>
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Add" cal:Message.Attach="Add('FileExtension')" />
                                <MenuItem Header="Remove" cal:Message.Attach="RemoveSelectedItems()" />
                                <MenuItem Header="Export" cal:Message.Attach="ExportSelectedItems()" />
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>
                </TabItem>
                <TabItem Header="Templates">
                    <ListView ItemsSource="{Binding Templates}" SelectedItem="{Binding SelectedViewModel}" ext:GridViewSort.AutoSort="True" >
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Name" 
                                                DisplayMemberBinding="{Binding Template.Name}"
                                                ext:GridViewSort.PropertyName="Template.Name"/>
                            </GridView>
                        </ListView.View>
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Add" cal:Message.Attach="Add('Template')" />
                                <MenuItem Header="Remove" cal:Message.Attach="RemoveSelectedItems()" />
                                <MenuItem Header="Export" cal:Message.Attach="ExportSelectedItems()" />
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>
                </TabItem>
                <TabItem Header="Classifications">
                    <ListView ItemsSource="{Binding Classifications}"
                              SelectedItem="{Binding SelectedViewModel}"
                              ext:GridViewSort.AutoSort="True"
                                >
                        <ListView.View>
                            <GridView>
                                
                                <GridViewColumn Header="Name" 
                                                DisplayMemberBinding="{Binding Classification.Name}"
                                                ext:GridViewSort.PropertyName="Classification.Name"/>
                            </GridView>
                        </ListView.View>
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Add" cal:Message.Attach="Add('Classification')" />
                                <MenuItem Header="Remove" cal:Message.Attach="RemoveSelectedItems()" />
                                <MenuItem Header="Export" cal:Message.Attach="ExportSelectedItems()" />
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>
                </TabItem>
            </TabControl>
            <GridSplitter Grid.Column="1" VerticalAlignment="Stretch"  Width="4" HorizontalAlignment="Stretch"/>


            <ContentControl Grid.Column="2" cal:View.Model="{Binding SelectedViewModel}" />

        </Grid>
    </DockPanel>
   
</UserControl>
